package com.ytjj.qmyx.admin.controller;


import com.ytjj.common.api.CommonResult;
import com.ytjj.common.api.ResultCode;
import com.ytjj.qmyx.admin.client.DataClient;
import com.ytjj.qmyx.admin.client.QuartzClient;
import com.ytjj.qmyx.mall.client.MallClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 刷新缓存
 */
@RestController
@RequestMapping("/configure")
public class RefreshCacheController {

    @Autowired
    private MallClient mallClient;
    @Autowired
    private DataClient dataClient;
    @Autowired
    private QuartzClient quartzClient;

    /**
     * 刷新缓存
     * @return
     */
    @GetMapping(value = "/refreshCache")
    public CommonResult refreshCache() {
        mallClient.reflushCash();
        return CommonResult.success(ResultCode.SUCCESS);
    }

    /**
     * 刷新渠道缓存
     */
    @GetMapping("/refreshChannelCache")
    public CommonResult refreshChannelCache() {
        dataClient.refreshPathCode();
        return CommonResult.success();
    }

    /**
     * 单个日期跑批渠道分成历史数据
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/batch/insert")
    public CommonResult batchInsert(
            @RequestParam(value = "startTime", required = false) String startTime,
            @RequestParam(value = "endTime", required = false) String endTime) {
        quartzClient.channelBatchInsert(startTime, endTime);
        return CommonResult.success();
    }

    /**
     * 多个日期跑批渠道分成历史数据
     * @param requestJson
     * @return
     */
    @PostMapping("/channel/batch/insert-p")
    public CommonResult batchInsertP(@RequestBody String requestJson) {
        quartzClient.channelBatchInsertP(requestJson);
        return CommonResult.success();
    }
}
